/**
 * fixed point arithmetic class
 * @author gordon
 */
public class FP {
	/**
	 * Fixed point shift
	 */
	public static final int FIX = 10;
	
	/**
	 * Some useful constants 
	 */
	public static final int ONE = 1 << FIX; 
	public static final int TWO = 2 << FIX;
	public static final int THREE = 3 << FIX;
	
	public static final int HALF = ONE>>1;
	public static final int QUARTER = HALF>>1;

    /**
     * fixed point multiplication
     * @param a
     * @param b
     * @return
     */
    public static int mul(int a, int b)
    {
        return (int) ( ((long) a * (long) b) >> FIX );
    }

    /**
     * fixed point division
     * @param a
     * @param b
     * @return
     */
    public static int div(int a, int b)
    {
        return (int) ( ((long)a << FIX) / (long) b );
    }

    /**
     * fixed point square root
     * @param a a fixed point number
     * @return the square root in fixed point
     */
    public static int sqrt(long a)
    {
        return (int) Math.sqrt( (double) a );
    }
    
}
